package com.example.waimaiandroid.billing;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;


import com.example.waimaiandroid.R;

public class remarkActivity extends AppCompatActivity {
    private EditText addRemark;
    private String remark;
    private ImageView myRemarkBack;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_remark);
        // 设置toolbar
        Toolbar toolbar = (Toolbar) findViewById(R.id.remarkToolBar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        initData();
        initView();
        initListener();

    }
    private void initData(){
        Intent intent = getIntent();
        remark = intent.getStringExtra("remark");

    }


    private void initView(){
        addRemark = findViewById(R.id.add_remark);
        if(null != remark && !"无".equals(remark)){
            addRemark.setText(remark);
        }
        myRemarkBack = findViewById(R.id.myRemarkBack);
    }

    private void initListener(){
        myRemarkBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                setResult(2,intent);
                finish(); // 直接finish()的话，resultCode 会默认为0 ，所以以后尽量不要使用0作为resultCode
            }
        });
    }



    // 添加toolBar的样式
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.remark_toolbar,menu);
        return true;
    }
    // 设置菜单监听事件

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        // 点击完成
        // 返回结果到 支付界面
        remark = addRemark.getText().toString();
        if(null == remark || "".equals(remark)){
            remark = "无";
        }
        Intent intent = new Intent();
        intent.putExtra("remark",remark);
        setResult(1,intent);
        finish();
        return super.onOptionsItemSelected(item);

    }
}